home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Diamond Collection
/
The Diamond Collection (Software Vault)(Digital Impact).ISO
/
cdr40
/
radserv.zip
/
UTIL.C
< prev
Wrap
C/C++ Source or Header
|
1994-11-15
|
2KB
|
108 lines
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void
UpperCase(cp)
char *cp;
{
for (; cp && *cp; cp++)
if (islower(*cp))
*cp = toupper(*cp);
}
char *
stripLeadingSpace(cp)
char *cp;
{
while (cp && *cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
cp++;
return cp;
}
void
stripTrailingSpace(s)
char *s;
{
register char *t;
if (!s)
return;
t = s + strlen(s) - 1;
while ((t >= s) && ((*t == ' ') || (*t == '\t') || (*t == '\n')))
t--;
t++;
*(t) = '\0';
}
/*
* Save a string in alloc'd memmory.
*/
char *
saveString(s)
char *s;
{
char *t;
HANDLE hgp;
hgp = GlobalAlloc(GPTR, strlen(s)+1);
if (hgp == NULL)
return NULL;
t = GlobalLock(hgp);
strcpy(t, s);
GlobalUnlock(hgp);
return t;
}
/*
* Allocate memory with error checking.
*/
char *
getline(buf, size, fp)
char *buf;
int size;
FILE *fp;
{
char lbuf[200];
char *cp;
if (!fp)
return NULL;
if (fgets(lbuf, sizeof(lbuf), fp) == NULL)
return NULL;
if (feof(fp))
return NULL;
cp = stripLeadingSpace(lbuf);
strncpy(buf, lbuf, size);
stripTrailingSpace(buf);
return buf;
}
int
cistrcmp(src,dst)
char *src,*dst;
{
char d[64],s[64];
register int i;
for (i=0; i<64 && *src; src++,i++)
if (isupper(s[i] = *src))
s[i] = tolower(s[i]);
s[i] = 0;
for (i=0; i<64 && *dst; dst++,i++)
if (isupper(d[i] = *dst))
d[i] = tolower(d[i]);
d[i] = 0;
return strcmp(s,d);
}